var searchType=-1;
var style=0;
function checkIp(value) { 

   var ip = value;
   var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;//正则表达式   
   if(ip=="")
   {
     value="";
     return [true,"",""];   
   }
   else if(re.test(ip))   
   {   
       if(RegExp.$1<256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256)
        return [true,"",""];   
   }     
   else
   {
   return [false,"ip格式输入有误!",""];    
   }
}
function checkMail(value) { 

   var mail = value;
   var re = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;  
   if(mail=="")
   {
     value="";
     return [false,"email格式输入有误!",""];   
   }
   else if(re.test(mail))   
   {   
     return [true,"",""];   
   }     
   else
   {
   return [false,"email格式输入有误!",""];    
   }
}


jQuery("#grid").jqGrid({        
   	url:'user_manager.php',
	datatype: "json",
	height: 200,
   	colNames:['记录编号','注册日期','用户名','真实姓名','权限','住址','手机','email','身份证号','身份证信息','身份证图片'],
   	colModel:[
   		{name:'ID',index:'ID',editable:true,editoptions:{readonly:true,size:10}, width:100},
   		{name:'DATE',index:'DATE',editable:true,editoptions:{readonly:true,size:10},width:100},
   		{name:'USERNAME',index:'USERNAME',editable:true,editoptions:{readonly:true,size:10},width:100},
   		{name:'REALNAME',index:'REALNAME',width:100},
	   {name:'TYPE',index:'TYPE',editable:true, width:100,	
	          edittype:"select", 	   
		       editoptions:{value:"0:禁止;1:可用"},
			    formoptions:{ rowpos:4,elmprefix:"&nbsp;&nbsp;&nbsp;&nbsp;" },
              editrules:{required:true}},
	   {name:'ADDRESS',index:'ADDRESS',width:100},
	    {name:'MOBILE',index:'MOBILE',width:100},
	   {name:'EMAIL',index:'EMAIL',width:100},
	   {name:'IDNUM',index:'IDNUM',width:100},
	   {name:'IDINFO',index:'IDINFO',width:100},
	   {name:'IDPIC',index:'IDPIC',width:100,hidden:true},
   	],
    width:"100%",
    rowNum:20,
    rowList:[10,20,30],
   	 mtype: "POST",
   	 pager: jQuery('#pgrid'),
   	 sortname: 'ID',
   	 viewrecords: true,
   	 multiselect:true,
   	 sortable: true,
    sortorder: "asc",
	 editurl:"user_manager.php?style=2",
    gridComplete: function(){
		var ids = jQuery("#grid").jqGrid('getDataIDs');
		for(var i=0;i < ids.length;i++){
			var cl = ids[i];
			be = "<input style='height:22px;width:100px;' type='button' id="+cl+" onclick=\"getAccessDetail(+"+cl+")\" value='详细信息'/>"; 
			jQuery("#grid").jqGrid('setRowData',ids[i],{IDINFO:be});
		}	
	}
});


$("#edit").click(function(){ var gr = jQuery("#grid").jqGrid('getGridParam','selrow'); 
if( gr != null ) jQuery("#grid").jqGrid('editGridRow',gr,{height:280,reloadAfterSubmit:true}); 
else alert("Please Select Row"); });




$("#del").click(function(){ 
var gr = jQuery("#grid").jqGrid('getGridParam','selarrrow');
var ids=new Array();
if( gr != null ){
var len = gr.length;
for (var i=0;i<len;i++)
{
var ret = jQuery("#grid").jqGrid('getRowData',gr[i]);
ids[i]=ret.ID;
}

jQuery("#grid").jqGrid('delGridRow',ids,{reloadAfterSubmit:true});
}
 
else alert("Please Select Row to delete!"); 
});

//functions 
function complexSearch(){
   	$( "#s" ).dialog( { 
	       width:350,  
          height:250, 
	       buttons: { 
	      "取消": function() { $(this).dialog("close"); },
	      "重置": function(){
	      jQuery("#username").attr("value","");
	       jQuery("#realname").attr("value","");
	      jQuery("#idnum").attr("value","");
	      jQuery("#from1").attr("value","");
	      jQuery("#to1").attr("value","");
	      
	      },
	      "提交":function(){

	           style=0
	           var id_mask = jQuery("#idnum").val();
	           var nm_mask=jQuery("#username").val();
	            $( "#from1" ).datepicker( "option", "dateFormat", "yy-mm-dd");
	            $( "#to1" ).datepicker( "option", "dateFormat", "yy-mm-dd");
              var from_mask = jQuery("#from1").val();
	           var to_mask = jQuery("#to1").val();
	           var real_mask = jQuery("#realname").val();
	           jQuery("#grid").jqGrid('setGridParam',{url:"user_manager.php?q=1&from_mask="+from_mask+"&to_mask="+to_mask+"&id_mask="+id_mask+"&real_mask="+real_mask+"&nm_mask="+nm_mask+"&style="+style,page:1}).trigger('reloadGrid'); 
	            jQuery("#grid").jqGrid('setGridParam',{url:"user_manager.php"}).trigger('reloadGrid'); 
	         }
	         },
	       close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			} });
   

}

function getAccessDetail(cl)
{
   var ret = jQuery("#grid").jqGrid('getRowData',cl);
   var idpic=ret.IDPIC;
   
   $("#idpic").attr("src",idpic);

  $( "#content" ).dialog({
	 	title: '详细信息',
	  width:200,  
    height:300,  
    modal:true
		});
   
}










